<template>
  <!-- 放置一个图标 -->
  <div>
    <!-- svg图标在这里只需要传文件名即可 -->
    <svg-icon
      :icon-class="isFullScreen?'exit-fullscreen':'fullscreen'"
      class="fullscreen"
      @click="toggleFullScreen"
    />
  </div>
</template>

<script>
import ScreenFull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isFullScreen: false // 切换svg图标数据项
    }
  },
  methods: {
    toggleFullScreen() {
      // 判断浏览器是否支持全屏
      if (ScreenFull.isEnabled) {
        // 支持的话调用全屏切换的方法
        this.isFullScreen = !this.isFullScreen
        ScreenFull.toggle()
      } else {
        this.$message.warning('您的浏览器版本过低，请升级')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  fill: #fff;
  cursor: pointer;
}
</style>
